//+------------------------------------------------------------------+ //| JC - Line Break Alert.mq4 | //| Juan Carlos Christensen. | //| http://www.eumefinancial.com | //+------------------------------------------------------------------+ #property copyright "Juan Carlos Christensen." #property link "http://www.eumefinancial.com" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Blue #property indicator_width1 2 //---- input parameters extern double Price1 = 2.0000; extern double Price2 = 2.0000; extern string Modes = "0- Line; 1- Channel"; extern int Mode = 1; extern bool UseSoundAlert = True; extern string SoundFile = "alert.wav"; extern int PlaySoundNTimes = 1; extern bool UseAlertPopUp = True; extern bool UseTickMode = True; extern bool UseSendMail = False; extern bool DeactivateOnAlert = True; extern color price1_color = Blue; extern color price2_color = Red; bool DidBreakout = False; double LastPrice; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators LastPrice=Bid; CreateLine("price1",price1_color,Price1); if(Mode==1) CreateLine("price2",price2_color,Price2); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectDelete("price1"); ObjectDelete("price2"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- double aPrice1=ObjectGet("price1",OBJPROP_PRICE1); if(GetLastError()==4202) CreateLine("price1",price1_color,Price1); if(aPrice1!=0 && aPrice1 != Price1) {Price1=aPrice1; Print("Price1 Changed:",Price1);} if(Mode==1) { double aPrice2=ObjectGet("price2",OBJPROP_PRICE1); if(GetLastError()==4202) CreateLine("price2",price2_color,Price2); if(aPrice2!=0 && aPrice2 != Price2) {Price2=aPrice2; Print("Price2 Changed:",Price2);} } if(Price1= Price1)) || ((LastPrice > Price1) && (CurrentPrice <= Price1)) && !DidBreakout) { if(DeactivateOnAlert) DidBreakout = True; if(UseSoundAlert) for(int x=0;x<=PlaySoundNTimes;x++) PlaySound(SoundFile); if(UseAlertPopUp) Alert(Symbol()," ",Period(),"Price Crossing Alert Line at ", Price1); //Symbol()," ",Period()," @ ",Bid if(UseSendMail) SendMail("Price Crossing Alert Line at " + Price1 + "!", "This is an email from the JC - Line Break Alert indicator. Price is crossing your alert line at " + Price1 + "!"); } } //+------------------------------------------------------------------+ void ChannelBreakOut() { double CurrentPrice=Bid; if((LastPrice < Price1) && (CurrentPrice >= Price1) && !DidBreakout) { if(DeactivateOnAlert) DidBreakout = True; if(UseSoundAlert) for(int x=0;x<=PlaySoundNTimes;x++) PlaySound(SoundFile); if(UseAlertPopUp) Alert(Symbol()," ",Period(),"Price Breaking Up at ", Price1); if(UseSendMail) SendMail("Channel Breaking Up at " + Price1 + "!", "This is an email from the JC - Line Break Alert indicator. Price broke up your channel alert line at " + Price1 + "!"); } if((LastPrice > Price2) && (CurrentPrice <= Price2) && !DidBreakout) { if(DeactivateOnAlert) DidBreakout = True; if(UseSoundAlert) for(x=0;x<=PlaySoundNTimes;x++) PlaySound(SoundFile); if(UseAlertPopUp) Alert(Symbol()," ",Period(),"Price Breaking Down at ", Price2); if(UseSendMail) SendMail("Channel Breaking Down at " + Price2 + "!", "This is an email from the JC - Line Break Alert indicator. Price broke down your channel alert line at " + Price2 + "!"); } } //+------------------------------------------------------------------+ void CreateLine(string aName, color aColor, double aPrice) { ObjectCreate(aName, OBJ_HLINE, 0, Time[0],aPrice); ObjectSet(aName, OBJPROP_COLOR, aColor); ObjectSet(aName, OBJPROP_STYLE, STYLE_DASH); }